package com.chaihu.admin.service.impl.menu;

import com.chaihu.admin.dao.MenuServiceDao;
import com.chaihu.bean.enums.MsgCode;
import com.chaihu.bean.in.admin.menu.QueryMenusIn;
import com.chaihu.bean.out.admin.menu.QueryMenusOut;
import com.chaihu.bean.result.ResponseResult;
import com.chaihu.intf.admin.menu.QueryMenusService;
import com.chaihu.intf.icommon.BaseService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
public class QueryMenusServiceImpl extends BaseService<ResponseResult<List<QueryMenusOut>>, QueryMenusIn> implements QueryMenusService {
    @Autowired
    private MenuServiceDao menuServiceDao;

    @Override
    public ResponseResult<List<QueryMenusOut>> checkHandle(ResponseResult<List<QueryMenusOut>> responseResult, QueryMenusIn in) {
        if (StringUtils.isEmpty(in.getDomain())) {
            responseResult.setCode(MsgCode.MSG_03012000.getCode());
            responseResult.setMsg(MsgCode.MSG_03012000.getMsg());
        }
        if (StringUtils.isEmpty(in.getUserId())) {
            responseResult.setCode(MsgCode.MSG_03012001.getCode());
            responseResult.setMsg(MsgCode.MSG_03012001.getMsg());
        }
        return responseResult;
    }

    @Override
    public ResponseResult<List<QueryMenusOut>> doHandle(ResponseResult<List<QueryMenusOut>> responseResult, QueryMenusIn in) {
        List<QueryMenusOut> queryMenusOuts = menuServiceDao.getMenus(in.getDomain(), in.getUserId());

        responseResult.setData(queryMenusOuts);
        return responseResult;
    }

    @Override
    public ResponseResult<List<QueryMenusOut>> respHandle(ResponseResult<List<QueryMenusOut>> responseResult, QueryMenusIn in) {
        return responseResult;
    }

    @Override
    public ResponseResult<List<QueryMenusOut>> queryMenus(QueryMenusIn in) {
        ResponseResult<List<QueryMenusOut>> result = new ResponseResult<>();
        return this.mainHandle(result, in);
    }
}
